package lg.minecraft.plugin.pokedex.command;

import com.cobblemon.mod.common.CobblemonNetwork;
import com.cobblemon.mod.common.api.pokedex.PokedexManager;
import com.cobblemon.mod.common.api.pokemon.PokemonSpecies;
import com.cobblemon.mod.common.api.storage.player.PlayerInstancedDataStoreTypes;
import com.cobblemon.mod.common.net.messages.client.SetClientPlayerDataPacket;
import com.cobblemon.mod.common.pokemon.Species;
import com.cobblemon.mod.common.util.PlayerExtensionsKt;
import lg.minecraft.plugin.library.command.CommandContext;
import lg.minecraft.plugin.library.command.CommandType;
import lg.minecraft.plugin.library.command.SubCommand;
import net.minecraft.class_3222;
import org.bukkit.entity.Player;

/**
 * @author langle__
 * @version 1.0
 */
public class SubRevokeCommand extends SubCommand {

    public SubRevokeCommand() {
        super("revoke");
    }

    @Override
    public String getPermission() {
        return "LGPokedex.command.revoke";
    }

    @Override
    public String getDescription() {
        return "扣除图鉴";
    }

    @Override
    public CommandType getCommandType() {
        return CommandType.PLAYER;
    }

    @Override
    public void onCommand(CommandContext context) {
        Player player = context.getPlayer();
        class_3222 nmsPlayer = PlayerExtensionsKt.getPlayer(player.getUniqueId());
        if (nmsPlayer == null) return;
        PokedexManager dexManager = PlayerExtensionsKt.pokedex(nmsPlayer);
        PokemonSpecies.INSTANCE.getSpecies().stream()
                .map(Species::getResourceIdentifier)
                .forEach(dexManager::deleteSpeciesRecord);

        dexManager.clearCalculatedValues();
        CobblemonNetwork.INSTANCE.sendPacket(nmsPlayer, new SetClientPlayerDataPacket(PlayerInstancedDataStoreTypes.INSTANCE.getPOKEDEX(), dexManager.toClientData(), false));
        player.sendMessage("[§6§lLG§ePokedex§f] 图鉴已扣除");
    }

}
